<?php
/**
 * FileName: SystemSettingBasicForm.php
 * Author: 790213952@qq.com
 * DateTime: 2024/8/7 下午12:34
 * SystemName: Ymtc
 *
 */


/**
 * FileName: SiteConfig.php
 * Author: Xiao Yao <790213952@qq.com>
 * DateTime: 2022-09-15 下午 02:23
 * Summary:
 */


namespace YmPhp\Admin\Http\Forms;


use YmPhp\Admin\Models\Setting as SystemSettingModel;
use YmPhp\Admin\Widgets\Form;
use Illuminate\Http\Request;

class SystemSettingSafeForm extends Form
{
    /**
     * The form title.
     *
     * @var string
     */
    public $title = '基本设置';

    /**
     * Handle the form request.
     *
     * @param Request $request
     *
     */
    public function handle(array $input)
    {
        (new SystemSettingModel())->saveConfig($input,'system_safe');
        return $this->response()->success('保存成功')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {

        $this->tab(trans('setting.safe.safe_settings'), function () {
            $this->column(6, function (Form $form) {
                $this->radio('show_logout', trans('setting.safe.show_logout'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.show_logout_msg'));
                $this->radio('open_logs', trans('setting.safe.open_logs'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.open_logs_msg'));
                $this->radio('hide_float_fix', trans('setting.safe.hide_float_fix'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('check_treaty', trans('setting.safe.check_treaty'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.check_treaty_msg'));
                $this->radio('content_copy', trans('setting.safe.content_copy'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.content_copy_msg'));
                $this->radio('open_pub_mod', trans('setting.safe.open_pub_mod'))
                    ->when(1, function (Form $form) {
                        $form->checkbox('open_pub_model', trans('setting.safe.open_pub_model'))
                            ->options(['info' => trans('menu.titles.info'), 'mall' => trans('menu.titles.mall'), 'business' => trans('menu.titles.business')])
                            ->saving(function ($value) {
                                return json_encode($value);
                            })->help(trans('setting.safe.content_copy_msg'));
                    })->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);


                $this->radio('hide_set_meal', trans('setting.safe.hide_set_meal'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.hide_set_meal_msg'));
                $this->radio('hide_pub_top', trans('setting.safe.hide_pub_top'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('pub_close_red', trans('setting.safe.pub_close_red'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('auto_sink', trans('setting.safe.auto_sink'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.auto_sink_msg'));
                $this->radio('close_sensitive', trans('setting.safe.close_sensitive'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('hide_top', trans('setting.safe.hide_top'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('hide_top_home', trans('setting.safe.hide_top_home'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.hide_top_home_msg'));
                $this->radio('auto_refresh', trans('setting.safe.auto_refresh'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
            });
            $this->width(9, 3);
        });
        $this->tab(trans('setting.safe.safe_content'), function () {
            $this->column(6, function (Form $form) {
                $this->radio('auto_ext_validity', trans('setting.safe.auto_ext_validity'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.auto_ext_validity_msg'));
                $this->radio('refresh_validity', trans('setting.safe.refresh_validity'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('show_expire_info', trans('setting.safe.show_expire_info'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('no_pic_info_handle', trans('setting.safe.no_pic_info_handle'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')])->help(trans('setting.safe.no_pic_info_handle_msg'));
                $this->radio('list_show_comment_num', trans('setting.safe.list_show_comment_num'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('list_show_drop_num', trans('setting.safe.list_show_drop_num'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('list_expire_admin_show', trans('setting.safe.list_expire_admin_show'))->options(['1'=>trans('setting.safe.list_expire_admin_show_1'),'2'=>trans('setting.safe.list_expire_admin_show_2'),'3'=>trans('setting.safe.list_expire_admin_show_3')]);
                $this->radio('close_index_notice', trans('setting.safe.close_index_notice'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('close_index_views', trans('setting.safe.close_index_views'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('ip_city', trans('setting.safe.ip_city'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->text('ip_prefix', trans('setting.safe.ip_prefix'))->icon('icon-navigation');
                $this->radio('letter_verify_check', trans('setting.safe.letter_verify_check'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('applet_verify_check', trans('setting.safe.applet_verify_check'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('one_mobile_binding_one_account', trans('setting.safe.one_mobile_binding_one_account'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('is_dial_login', trans('setting.safe.is_dial_login'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);
                $this->radio('is_del_comment', trans('setting.safe.is_del_comment'))->options(['0'=>trans('setting.basic.close'),'1'=>trans('setting.basic.open')]);

            });

        });
    }

    /**
     * The data of the form.
     *
     * @return array $data
     */
    public function data()
    {
        $datas = SystemSettingModel::pluck('value', 'key');
        return $datas['system_safe'];
    }


}

